🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / repository / src / commonMain / kotlin / org / meshtastic / core / repository / NodeRestartTracker.kt
Displaying Raw • Download
core/repository/src/commonMain/kotlin/org/meshtastic/core/repository/NodeRestartTracker.kt bc4e9da3ad7a2a22768cbaecc75810e018bc40e2 (bc4e9da3) Text, 2.85 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.repository
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.Job
Tff7b72import T7ee787kotlinx.coroutines.delay
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.asStateFlow
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787kotlin.time.Duration
Tff7b72import T7ee787kotlin.time.Duration.Companion.seconds
T8b949e/**
* Tracks a window in which the locally connected node is expected to restart (a config save the firmware applies with a
* reboot, or an explicit reboot command). While the window is open, an observed transport disconnect is the expected
* consequence of the restart — the UI presents "restarting" instead of the alarming disconnected state, and the
* foreground-service notification stays on a connecting presentation.
*
* The window closes when the node completes its post-reboot config handshake ([onConnected]) or after [DEFAULT_WINDOW]
* if the node never comes back — after that, a persisting disconnect is a real problem and is shown as one.
*/
Tff7b72class T56d364NodeRestartTrackerTb4b4b4(Tff7b72private Tff7b72val Te6edf3scopeTb4b4b4: Te6edf3CoroutineScopeTb4b4b4) Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3_restartExpected Tff7b72= Te6edf3MutableStateFlowTb4b4b4(Tff7b72falseTb4b4b4)
T8b949e/** True while a node restart (and its transport disconnect) is expected. */
Tff7b72val Te6edf3restartExpectedTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657BooleanTff7b72> Tff7b72= Te6edf3_restartExpectedTb4b4b4.Te6edf3asStateFlowTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72var Te6edf3expiryJobTb4b4b4: Te6edf3Job? Tff7b72= Tff7b72null
T8b949e/** Opens (or extends) the expected-restart window. Call at the moment the restart-causing action is sent. */
Tff7b72fun Td2a8ffexpectRestartTb4b4b4(Te6edf3windowTb4b4b4: Te6edf3Duration Tff7b72= Te6edf3DEFAULT_WINDOWTb4b4b4) Tb4b4b4{
Te6edf3expiryJobTff7b72?.Te6edf3cancelTb4b4b4(Tb4b4b4)
Te6edf3_restartExpectedTb4b4b4.Te6edf3value Tff7b72= Tff7b72true
Te6edf3expiryJob Tff7b72=
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Te6edf3delayTb4b4b4(Te6edf3windowTb4b4b4)
Te6edf3_restartExpectedTb4b4b4.Te6edf3value Tff7b72= Tff7b72false
Tb4b4b4}
Tb4b4b4}
T8b949e/** Closes the window; call when the node is fully back online (config handshake complete). */
Tff7b72fun Td2a8ffonConnectedTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3expiryJobTff7b72?.Te6edf3cancelTb4b4b4(Tb4b4b4)
Te6edf3expiryJob Tff7b72= Tff7b72null
Te6edf3_restartExpectedTb4b4b4.Te6edf3value Tff7b72= Tff7b72false
Tb4b4b4}
Tff7b72companion Tff7b72object Tb4b4b4{
T8b949e/** Covers reboot delay (~5s), boot (~10-25s), reconnect and config sync (~10-30s) with headroom. */
Tff7b72val Te6edf3DEFAULT_WINDOW Tff7b72= T79c0ff9T79c0ff0.Te6edf3seconds
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s